package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Classinfo;
import cn.wolfcode.mapper.ClassinfoMapper;
import cn.wolfcode.query.QueryObject;
import cn.wolfcode.service.IClassinfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassinfoImplService implements IClassinfoService {
    @Autowired
    private ClassinfoMapper classinfoMapper;

    public void save (Classinfo classinfo) {
        classinfoMapper.insert(classinfo);
    }

    public void updateById (Classinfo classinfo) {
        classinfoMapper.updateByPrimaryKey(classinfo);
    }

    public void deleteById (Long id) {
        classinfoMapper.deleteByPrimaryKey(id);
    }

    public Classinfo selectById (Long id) {
        return classinfoMapper.selectByPrimaryKey(id);
    }

    public List<Classinfo> listAll () {
        return classinfoMapper.selectAll();
    }

    public PageInfo<Classinfo> query (QueryObject qo) {
        //告诉pagehelper我们的分页参数(只对下一句sql进行自动分页)
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Classinfo> result = classinfoMapper.queryForList(qo);
        return new PageInfo<>(result);
    }
}
